package com.beiding.v2.grammar;

import com.beiding.v2.base.IContext;
import com.beiding.v2.base.IUnitHandler;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Context implements IContext {

    private List<IUnitHandler> handlers = new ArrayList<>();

    public void addHandler(IUnitHandler... unitHandlers) {
        Collections.addAll(handlers, unitHandlers);
    }


    public void addHandler(int index, IUnitHandler... unitHandlers) {
        for (int i = 0; i < unitHandlers.length; i++) {
            handlers.add(index + i, unitHandlers[i]);
        }
    }

    public void removeHandler(IUnitHandler... unitHandlers) {
        for (IUnitHandler unitHandler : unitHandlers) {
            handlers.remove(unitHandler);
        }
    }

    @Override
    public List<IUnitHandler> getHandlers() {
        return handlers;
    }

}
